ABC154 D - Dice in Line
https://atcoder.jp/contests/abc154/tasks/abc154_d
提出
TLE
code: python
n, k = map(int, input().split())
p = list(map(int, input().split()))
except_values = []
for i in range(n):
res = 0
for j in range(1, pi+1):
res += j
except_values.append(res / pi)
ans = -1
for i in range(n-k+1):
res = sum(except_valuesi:i+k)
if (res > ans):
ans = res
print(ans)
解答
code: python
n, k = map(int, input().split())
p = list(map(int, input().split()))
except_values = []
for i in range(n):
except_values.append((pi + 1) / 2)
# 9.0, 7.0, 7.0, 6.5, 8.0, 10.5, 5.5, 7.0, 9.0, 6.0
ans = sum(except_values:k)
res = ans
for i in range(k, n):
res = res + except_valuesi - except_valuesi-k
if res > ans:
ans = res
print(ans)
テーマ
#cumulativeSum
メモ
Atcoder ABC 154 D - Dice in Lineをpythonで解く
提出
code: python
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))
exception = []
for i in range(1, 1001):
exc = 0.0
for j in range(1, i+1):
exc += j * (1/i)
exception.append(exc)
# 合計が多い範囲を求めたい
# 17 13 13 12 15 20 10 13 17 11
# t r
ans = -1
tmp = 0.0
# 0 ~ 3
for i in range(k):
tmp += exception[pi-1]
# 4~
for i in range(k, len(p)):
res = tmp
res += exception[pi-1]
res -= exception[pi-k-1]
if res > ans:
ans = res
if ans == -1:
print(tmp)
else:
print(ans)
メモ
方針は合ってる